extends Chara
func _ready():
	pass
func _init():
	print("小奥拉，欢迎回到奥拉星")
	call_deferred("alxUtilsInit")
	pass
func _connect():
	pass


var lv1 = []
var lv2 = []
var lv3 = []
var lv4 = []
const bf = globalData.infoDs["g_alxBuffs"]
const buff = globalData.infoDs["g_alxBuffs"]
var path
var base

#按照舰种+等级存储的角色ID字典
var shipTypeDic = {}

#从字典中进行检索，若没有则返回默认值
func dicGet(dic, field, default):
	var f = dic.get(field)
	if f == null:
		return default
	else:
		return f

#对字典指定字段进行append
func dicAppend(dic, field, obj):
	var f = dic.get(field)
	if f == null:
		dic[field] = [obj]
	else:
		dic[field].append(obj)

#初始化
func alxUtilsInit():
	base = globalData.infoDs["g_alxBase"]
	path = chaData.infoDs["calxhx"].dir

#创建图片容器
func cTr(file):
	var obj = TextureRect.new()
	obj.set_texture(base.loadImg(path, file))
	return obj

func createImageTexture(file):
	return base.loadImg(path, file)
#创建图片
func cIt(file):
	return base.loadImg(path, file)

#根据cha获得一个随机敌方单位
func getRndEnemy(cha):
	var chas = cha.getAllChas(1)
	if chas == null or chas.empty():
		return null
	else:
		return sys.rndListItem(chas)
#根据cha获得一个随机友方单位
func getRndAlly(cha):
	return sys.rndListItem(cha.getAllChas(2))

#从当前池子中获得随机人物
func getRndCha(buff = 0):
	var rngnum = sys.rndRan(1, 1000)
	var rng = ""
	if rngnum <= 5 + buff:
		rng = sys.rndListItem(lv4)
	elif rngnum <= 160 + buff:
		rng = sys.rndListItem(lv3)
	else:
		rng = sys.rndListItem(lv1)
	return sys.main.newChara(rng)

func fillShipTypeDic():
	for i in lv1:
		doFillShipTypeDic(i)
	for i in lv2:
		doFillShipTypeDic(i)
	for i in lv3:
		doFillShipTypeDic(i)
	for i in lv4:
		doFillShipTypeDic(i)

func doFillShipTypeDic(id):
	var cha = sys.main.newChara(id)
	cha._extInit()
	var fromType = cha.chaName.rsplit("「")[1].rsplit("」")[0]
	var typeDic = dicGet(shipTypeDic, fromType, {})
	dicAppend(typeDic, String(cha.lv), cha.id)
	shipTypeDic[fromType] = typeDic
	cha.queue_free()